<?php
//error_reporting(0);

/**
 * TODO:
 * Opravljaj sproti!!!!
 * DOKUMENTACIJA API-ja:
 * https://docs.google.com/spreadsheet/ccc?key=0AsRgUN7Zsq_VdHA1OTh5SGZfOXZVOUlwOHFaR3g2U3c#gid=0
 *
 */

include "./helperScripts/database.php";

// Script for checking close cards and sending email
include "./timeManagement/sendMailForCloseCards.php";

$action = "";
if ( isset($_GET['action']) )
{
	$action = $_GET['action'];
} else if ( isset ($_POST['action']) )
{
	$action = $_POST['action'];
} else
{
	echo jsonError('No action parameter provided!');
	die();
}


// Test action provided and include appropriate php script
// IMPORTANT:
// In every script return json with parameter success: true/false, if false provide reason

// You must return json with parameters success: true and user_id: number
// If failure success: false and reason: "user-friendly string what went wrong".
switch ($action)
{
	//USER MANAGEMENT
	case "login":
		include "./userManagement/loginUser.php";
		break;
	case "addUser":
		include "./userManagement/addUser.php";
		break;
	case "toggleUser":
		include "./userManagement/toggleUser.php";
		break;
	case "lockUser":
		include "./userManagement/lockUser.php";
		break;
	case "getUsers":
		include "./userManagement/getUsers.php";
		break;

	// GROUP MANAGEMENT
	case "getGroups":
		include "./developmentGroup/getGroups.php";
		break;
	case "addGroup":
		include "./developmentGroup/addDevGroup.php";
		break;
	case "toggleUserGroup":
		include "./developmentGroup/toggleUser.php";
		break;
	case "addUserGroup":
		include "./developmentGroup/addUser.php";
		break;
	case "newKanbanMaster":
		include "./developmentGroup/newKanbanMaster.php";
		break;
	case "newProductOwner":
		include "./developmentGroup/newProductOwner.php";
		break;

	// PROJECT MANAGEMENT
	case "addProject":
		include "./projectManagement/addProject.php";
		break;
	case "getProjects":
		include "./projectManagement/getProjects.php";
		break;
	case "deleteProject":
		include "./projectManagement/deleteProject.php";
		break;


	// BOARD MANAGEMENT
	case "createBoard":
		include "./boardManagement/createBoard.php";
		break;
	case "addColumnToBoard":
		include "./boardManagement/addColumnToBoard.php";
		break;
	case "getBoards":
		include "./boardManagement/getBoards.php";
		break;
	case "getUserBoards":
		include "./boardManagement/getUserBoards.php";
		break;
	case "removeColumn":
		include "./boardManagement/removeColumn.php";
		break;
	case "duplicateBoard":
		include "./boardManagement/duplicateBoard.php";
		break;
	case "editColumn":
		include "./boardManagement/editColumn.php";
		break;

	// CARD MANAGEMENT
	case "createCard":
		include "./cardManagement/createCard.php";
		break;
	case "getCards":
		include "./cardManagement/getCards.php";
		break;
	case "moveCard":
		include "./cardManagement/moveCard.php";
		break;
	case "getCardLog":
		include "./cardManagement/getLog.php";
		break;
	case "deleteCard":
		include "./cardManagement/deleteCard.php";
		break;

	// TIME MANAGEMENT
	case "calculateAverageCardsTime":
		include "./timeManagement/calculateAverageCardsTime.php";
		break;

	case "graph":
		include "./graph/comulative.php";
		break;
	/*	case "test":
			include "./documentation/test.php";
			break;*/
	// DEFAULT
	default :
		echo jsonError('Action parameter (%s) not handled!!! Contact lazy developers =)', [$action]);
}
